﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="SequenceNullabilityOfBuiltInTypes", Namespace="http://kis.x-road.eu/", Target=typeof(SequenceNullabilityOfBuiltInTypes))]
    public class SequenceNullabilityOfBuiltInTypesSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected SequenceNullabilityOfBuiltInTypes clazz;
        
        public SequenceNullabilityOfBuiltInTypesSerializer(SequenceNullabilityOfBuiltInTypes clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("XsdStringNil");
            if (clazz.XsdStringNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.XsdStringNil))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdStringNonNil");
            if (clazz.XsdStringNonNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.XsdStringNonNil))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : XsdStringNonNil");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdDateTimeNil");
            if (clazz.XsdDateTimeNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.XsdDateTimeNil))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdDateTimeNonNil");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.XsdDateTimeNonNil))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdDurationNil");
            if (clazz.XsdDurationNil!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDuration(((System.TimeSpan)(clazz.XsdDurationNil))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdDurationNonNil");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDuration(((System.TimeSpan)(clazz.XsdDurationNonNil))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdBooleanNillable");
            if (clazz.XsdBooleanNillable!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.XsdBooleanNillable))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdBooleanNonNillable");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.XsdBooleanNonNillable))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdUnsignedIntNillable");
            if (clazz.XsdUnsignedIntNillable!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.XsdUnsignedIntNillable))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("XsdUnsignedIntNonNillable");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdUnsignedShort(((ushort)(clazz.XsdUnsignedIntNonNillable))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="XsdStringNil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.XsdStringNil = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("XsdStringNil")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdStringNil", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdStringNonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceNullabilityOfBuiltInTypes>XsdStringNonNil");
                }
                clazz.XsdStringNonNil = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("XsdStringNonNil")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdStringNonNil", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdDateTimeNil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.XsdDateTimeNil = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("XsdDateTimeNil")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdDateTimeNil", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdDateTimeNonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceNullabilityOfBuiltInTypes>XsdDateTimeNonNil");
                }
                clazz.XsdDateTimeNonNil = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("XsdDateTimeNonNil")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdDateTimeNonNil", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdDurationNil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.XsdDurationNil = new global::Xtee.Core.Schema.XsdDuration(Reader.ReadElementString("XsdDurationNil")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdDurationNil", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdDurationNonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceNullabilityOfBuiltInTypes>XsdDurationNonNil");
                }
                clazz.XsdDurationNonNil = new global::Xtee.Core.Schema.XsdDuration(Reader.ReadElementString("XsdDurationNonNil")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdDurationNonNil", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdBooleanNillable") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.XsdBooleanNillable = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("XsdBooleanNillable")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdBooleanNillable", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdBooleanNonNillable") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceNullabilityOfBuiltInTypes>XsdBooleanNonNillable");
                }
                clazz.XsdBooleanNonNillable = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("XsdBooleanNonNillable")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdBooleanNonNillable", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdUnsignedIntNillable") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.XsdUnsignedIntNillable = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("XsdUnsignedIntNillable")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdUnsignedIntNillable", Reader.LocalName);
            }
            if (Reader.LocalName=="XsdUnsignedIntNonNillable") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceNullabilityOfBuiltInTypes>XsdUnsignedIntNonNillable");
                }
                clazz.XsdUnsignedIntNonNillable = new global::Xtee.Core.Schema.XsdUnsignedShort(Reader.ReadElementString("XsdUnsignedIntNonNillable")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfBuiltInTypes>XsdUnsignedIntNonNillable", Reader.LocalName);
            }
        }
    }
}
